/*******************************************************************************
 *  Copyright (c) 2010 Chase Technology Ltd.
 *  
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the GNU General Public License v3.0
 *  which is available at http://www.gnu.org/licenses/
 * 
 * Contributors:
 *     Doug Satchwell - initial API and implementation
 *******************************************************************************/
package org.jfunction.ui.internal.editor;

import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.source.ISharedTextColors;
import org.eclipse.swt.SWT;
import org.jfunction.internal.parser.JFunctionToken;
import org.jfunction.internal.parser.KeyWords;
import org.jfunction.internal.parser.ScenarioScanner;

public class ColourScenarioScanner extends ScenarioScanner {

	private final IToken defaultToken;
	private final IToken scenarioToken;
	private final IToken stepToken;
	private final IToken commentToken;
	private final IToken fieldToken;
	
	public ColourScenarioScanner(KeyWords keywords, ISharedTextColors sharedColors) {
		super(keywords);
		commentToken = new Token(new TextAttribute(sharedColors.getColor(P4ColorConstants.COMMENT)));
		scenarioToken = new Token(new TextAttribute(sharedColors.getColor(P4ColorConstants.SCENARIO),null,SWT.BOLD));
		stepToken = new Token(new TextAttribute(sharedColors.getColor(P4ColorConstants.DEFAULT),null,SWT.BOLD));
		fieldToken = new Token(new TextAttribute(sharedColors.getColor(P4ColorConstants.FIELD)));
		defaultToken = new Token(new TextAttribute(sharedColors.getColor(P4ColorConstants.DEFAULT)));
	}

	@Override
	public IToken nextToken() {
		IToken token = super.nextToken();
		if (token.isEOF() || token.isUndefined() || token.isWhitespace())
			return token;
		if (token instanceof JFunctionToken) {
			switch((JFunctionToken)token) {
			case SCENARIO:
				return scenarioToken;
			case STEP:
				return stepToken;
			case FIELD:
				return fieldToken;
			case COMMENT:
				return commentToken;
			}
		}
		return defaultToken;
	}
}
